<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java集合框架性能优化实战指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block::before {
            content: 'JAVA';
            position: absolute;
            top: 8px;
            right: 12px;
            font-size: 12px;
            color: #666;
            font-weight: 600;
            letter-spacing: 1px;
        }
        
        .section-title {
            position: relative;
            display: inline-block;
        }
        
        .section-title::after {
            content: '';
            position: absolute;
            bottom: -8px;
            left: 0;
            width: 60px;
            height: 4px;
            background: linear-gradient(90deg, #667eea, #764ba2);
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
            position: relative;
            overflow: hidden;
        }
        
        .highlight-box::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: pulse 3s ease-in-out infinite;
        }
        
        @keyframes pulse {
            0%, 100% { transform: scale(1); opacity: 0.5; }
            50% { transform: scale(1.1); opacity: 0.3; }
        }
        
        .tip-card {
            background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
            color: #333;
            padding: 16px 20px;
            border-radius: 8px;
            margin: 16px 0;
            font-weight: 500;
            box-shadow: 0 4px 15px rgba(250, 112, 154, 0.3);
        }
        
        .performance-metric {
            background: #f8f9fa;
            border-left: 4px solid #667eea;
            padding: 12px 20px;
            margin: 16px 0;
            border-radius: 4px;
        }
        
        .mermaid {
            margin: 30px auto;
            text-align: center;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0.1em 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                Java集合框架<br>
                <span class="text-3xl md:text-4xl opacity-90">性能优化实战指南</span>
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl">
                <i class="fas fa-quote-left mr-2"></i>
                十年大厂经验凝结，让你的代码性能飞起来
                <i class="fas fa-quote-right ml-2"></i>
            </p>
            <div class="mt-8 flex flex-wrap gap-4 text-sm">
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                    <i class="fas fa-clock mr-2"></i>阅读时间：15分钟
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                    <i class="fas fa-fire mr-2"></i>性能提升：20倍+
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                    <i class="fas fa-users mr-2"></i>适合：中高级开发者
                </span>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-5xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">作</span>为一个在互联网大厂摸爬滚打多年的Java老兵，我不知道踩过多少集合框架的坑，也不记得因为集合性能问题被多少次半夜call out来救火。有时候我都在想，要是早点整理这些经验，该省多少通宵加班的命啊！所以今天就把这些年踩过的坑和积累的技巧分享给大家，希望你少走弯路。
            </p>
        </div>

        <!-- 数据可视化：集合框架概览 -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h3 class="text-2xl font-bold mb-6 text-gray-800">
                <i class="fas fa-sitemap mr-3 text-purple-600"></i>Java集合框架全景图
            </h3>
            <div class="mermaid">
                graph TD
                    A[Java集合框架] --> B[List接口]
                    A --> C[Set接口]
                    A --> D[Map接口]
                    A --> E[Queue接口]
                    
                    B --> B1[ArrayList<br/>随机访问O1]
                    B --> B2[LinkedList<br/>两端操作O1]
                    B --> B3[Vector<br/>线程安全]
                    
                    C --> C1[HashSet<br/>无序快速]
                    C --> C2[TreeSet<br/>有序]
                    C --> C3[LinkedHashSet<br/>插入顺序]
                    
                    D --> D1[HashMap<br/>最常用]
                    D --> D2[TreeMap<br/>键排序]
                    D --> D3[LinkedHashMap<br/>插入顺序]
                    D --> D4[ConcurrentHashMap<br/>并发安全]
                    
                    E --> E1[PriorityQueue<br/>优先级队列]
                    E --> E2[ArrayDeque<br/>双端队列]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style E fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Section 1: 集合选择 -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-compass mr-3 text-purple-600"></i>集合选择
            </h2>
            
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                Java集合就像厨房里的各种工具，看起来都能用，但用错了不仅浪费时间还可能把菜做砸。我曾经看过一个实习生用LinkedList来做频繁随机访问的操作，结果API响应时间飙到了几秒钟。项目紧急上线，我们只能通宵达旦重构代码，把集合换成ArrayList，性能立马提升了20倍。
            </p>

            <div class="code-block p-6 my-6">
                <pre><code>// 千万别这么干！随机访问用LinkedList简直是自杀
LinkedList&lt;UserProfile&gt; users = new LinkedList&lt;&gt;();
// 大量数据导入...
for (int i = 0; i &lt; 10000; i++) {
    UserProfile user = users.get(i); // 这里每次get都是O(n)的灾难
    processUser(user);
}</code></pre>
            </div>

            <div class="highlight-box">
                <h4 class="text-xl font-bold mb-4">
                    <i class="fas fa-lightbulb mr-2"></i>集合选择铁律
                </h4>
                <div class="grid md:grid-cols-2 gap-4 relative z-10">
                    <div class="bg-white bg-opacity-20 rounded-lg p-4">
                        <strong class="text-lg">ArrayList</strong>
                        <p class="mt-1">顺序访问、随机访问的首选，但别傻傻地频繁在中间插入删除</p>
                    </div>
                    <div class="bg-white bg-opacity-20 rounded-lg p-4">
                        <strong class="text-lg">LinkedList</strong>
                        <p class="mt-1">频繁在两端增删元素的场景才考虑用，比如实现队列</p>
                    </div>
                    <div class="bg-white bg-opacity-20 rounded-lg p-4">
                        <strong class="text-lg">HashMap</strong>
                        <p class="mt-1">绝大多数key-value场景的首选，但记得预估容量</p>
                    </div>
                    <div class="bg-white bg-opacity-20 rounded-lg p-4">
                        <strong class="text-lg">TreeMap</strong>
                        <p class="mt-1">只有当你需要key自然排序时才用，否则性能比HashMap差太多</p>
                    </div>
                </div>
            </div>

            <div class="performance-metric">
                <i class="fas fa-chart-line mr-2 text-purple-600"></i>
                <strong>实战案例：</strong>某同事用TreeMap存储几万用户信息，系统响应时间从300ms飙升到1.2秒。改用HashMap后，立即恢复正常。
            </div>
        </div>

        <!-- Section 2: 预分配容量 -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-expand-arrows-alt mr-3 text-purple-600"></i>预分配容量
            </h2>

            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                如果说我在审代码时最痛恨看到的是什么，那绝对是这行：
            </p>

            <div class="code-block p-6 my-6">
                <pre><code>ArrayList&lt;SomeObject&gt; list = new ArrayList&lt;&gt;(); // 默认容量小得可怜</code></pre>
            </div>

            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                尤其是接下来往里面塞上万条数据时。讲真，不预分配容量的行为在我看来就是性能灾难的前奏。
            </p>

            <div class="tip-card">
                <i class="fas fa-exclamation-triangle mr-2"></i>
                我之前参与的一个电商大促项目，就因为没有合理预分配容量，导致大促瞬间流量涌入时，系统CPU使用率飙升到90%以上。
            </div>

            <div class="grid md:grid-cols-2 gap-6 my-8">
                <div class="bg-red-50 border-2 border-red-200 rounded-lg p-6">
                    <h4 class="text-xl font-bold text-red-700 mb-3">
                        <i class="fas fa-times-circle mr-2"></i>灾难版本
                    </h4>
                    <div class="code-block p-4 text-sm">
                        <pre><code>ArrayList&lt;Order&gt; orders = new ArrayList&lt;&gt;(); 
// 默认容量10
for (int i = 0; i &lt; 100000; i++) { 
    orders.add(new Order()); 